<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>WebSocket客户端</title>
	<script type="text/javascript">
	var socket ;
	if(window.WebSocket){
		socket = new WebSocket("ws://localhost:8081/ttbj-web-applet/applet.do?openId=11111");
		socket.onmessage = function(event){
			var ta = document.getElementById("responseText");
			ta.value = ta.value+"\n"+event.data;
		}
		
		socket.onopen = function(event){
			var ta = document.getElementById("responseText");
			ta.value = "连接开启";
		}
		
		socket.onclose = function(event){
			document.getElementById("responseText");
			ta.value =  ta.value+"\n"+ "连接断掉";
		}
	}else{
		alert("浏览器不支持websocket");
		
	}
	
	function sender(message) {
		if(!window.WebSocket){
			return;
		}
		if(socket.readyState == WebSocket.OPEN){
			socket.send(message)
		}else{
			alert("连接未开启!")
		}
	}
	</script>
</head>
<body>
	<form action="">
		<textarea rows="" cols="" name="message" style="width: 400px; height: 200px">
		</textarea>
		<input type="button" value="发送" onclick="sender(this.form.message.value)" />
		<h3>服务端输出：</h3>
		<textarea id="responseText" style="width: 400px; height: 200px"></textarea>
		<input type="button" onclick="javascript:document.getElementById('responseText').value=''" value="清除" />
	</form>


</body>
</html>